/**
 * 
 */
package com.seascape.swms.framework.model;

/**
 * @author Lay
 *
 */
public class Result {

	private String code;
	private String msg;
	private Object data;

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	@Override
	public String toString() {
		return "code=" + code + " message=" + msg + " data=" + data;
	}

	public static Result fail() {
		Result ret = new Result();
		ret.setCode(ReturnCode.FAIL.getCode());
		ret.setMsg(ReturnCode.FAIL.getDesc());
		return ret;
	}

	public static Result fail(Object data) {
		Result ret = Result.fail();
		ret.setData(data);
		return ret;
	}

	public static Result failMessage(String msg) {
		Result ret = Result.fail();
		ret.setMsg(msg);
		return ret;
	}

	public static Result successMessage(String msg) {
		Result ret = Result.success();
		ret.setMsg(msg);
		return ret;
	}

	public static Result success() {
		Result ret = new Result();
		ret.setCode(ReturnCode.SUCCESS.getCode());
		ret.setMsg(ReturnCode.SUCCESS.getDesc());
		return ret;
	}

	public static Result success(Object data) {
		Result ret = Result.success();
		ret.setData(data);
		return ret;
	}

	public static Result http404(Object data) {
		Result ret = new Result();
		ret.setCode(ReturnCode.NOT_FOUND.getCode());
		ret.setMsg(ReturnCode.NOT_FOUND.getDesc());
		ret.setData(data);
		return ret;
	}

	public static Result http403(Object data) {
		Result ret = new Result();
		ret.setCode(ReturnCode.ACCESS_ERROR.getCode());
		ret.setMsg(ReturnCode.ACCESS_ERROR.getDesc());
		ret.setData(data);
		return ret;
	}
	
	public static Result unauth() {
		Result ret = new Result();
		ret.setCode(ReturnCode.NOT_LOGIN.getCode());
		ret.setMsg(ReturnCode.NOT_LOGIN.getDesc());
		return ret;
	}

	public enum ReturnCode {

		NOT_LOGIN("401", "未登录"), SUCCESS("200", "成功"), FAIL("500", "内部失败"), ACCESS_ERROR("403",
				"禁止访问"), NOT_FOUND("404", "页面未发现");
		private String code;
		private String desc;

		ReturnCode(String code, String desc) {
			this.code = code;
			this.desc = desc;
		}

		public String getCode() {
			return code;
		}

		void setCode(String code) {
			this.code = code;
		}

		public String getDesc() {
			return desc;
		}

		void setDesc(String desc) {
			this.desc = desc;
		}
	}
}
